package com.liuyi.netty.im.lychat;

import cn.hutool.core.util.EnumUtil;
import cn.hutool.crypto.SecureUtil;
import com.liuyi.netty.im.commons.codes.CodeConst;
import com.liuyi.netty.im.lychat.modular.enums.SessionType;
import com.liuyi.netty.im.server.util.ImHelp;

/**
 * 常量
 *
 * @author Mr.Fmy
 * @since 2021/12/25
 */
public interface LychatConst {

    String DEFAULT_USER_HEAD = "http://lychat.gitliuyi.top/images/default_user_head.jpg";

    String DEFAULT_GROUP_HEAD = "http://lychat.gitliuyi.top/images/default_group_head.jpg";

    String SYS_USER_ID = "lycaht";

    /**
     * 群最大人数
     */
    Integer GROUP_MAX_NUMBER = 500;

    static boolean checkUserPassword(String password, String md5Password, String salt) {
        return md5UsserPassword(password, salt).equals(md5Password);
    }

    static String md5UsserPassword(String password, String salt) {
        return SecureUtil.md5(salt.concat(password));
    }

    static SessionType getSessionType(String sessionId) {
        return EnumUtil.fromString(SessionType.class, ImHelp.sessionIdToType(sessionId).name());
    }

    static String sessionId(String toId,SessionType sessionType) {
        return ImHelp.sessionId(EnumUtil.fromString(CodeConst.SessionType.class, sessionType.name()),toId);
    }
}
